import { cb } from "../util/iteratee";
import { isArrayLike } from "./each";

export default function map<T>(obj: T[], iteratee: (value: T, index: string | number, obj: T[]) => any, context?) {
  iteratee = cb(iteratee, context)
  var keys = !isArrayLike(obj) && Object.keys(obj)
  var length = (keys || obj).length
  var resluts = Array(length)
  for (var index = 0; index < length; index++) {
    const currentKey = keys ? keys[index] : index
    resluts[index] = iteratee(obj[currentKey], currentKey, obj)
  }
  return resluts
}